﻿// Dự án: QLNHK 2.0, File: UltraGridControls.cs
// Namespace: QLNHK.HETHONG, Class: UltraGridControls
// Số dòng code: 96, Kích thước file: 3.08 KB
// Ngày tạo: 4/25/2006 8:53 AM
// Ngày chỉnh sửa: 7/1/2006 8:23 AM
#region Using directives
using System;
using Infragistics.Win.UltraWinGrid;
using Infragistics.Win.UltraWinTree;
using Infragistics.Win.UltraWinEditors;
using Infragistics.Win;
using System.Windows.Forms;
using System.Drawing;
#endregion

/// <summary>
/// Softech. desktop. UI.HETHONG
/// </summary>
namespace QLNHK.Controls
{
	/// <summary>
	/// Summary description for UltraGridControls.
	/// </summary>
	public class UltraGridControls
	{
		private UltraGridControls()
		{
		} // UltraGridControls()
        #region Style Grid
        /// <summary>
        /// Thiết lập màu sắc và kiểu định dạng của lưới
        /// </summary>
        /// <param name="UGrid"></param>
        public static void SetGridStyle(UltraGrid UGrid)
        {
            UltraGridBand UGridBand = UGrid.DisplayLayout.Bands[0];
            
            //Thiết lập màu sắc hiển thị Error của data trên Grid
            UGridBand.Override.SupportDataErrorInfo = SupportDataErrorInfo.RowsAndCells;
            //UGridBand.Override.DataErrorCellAppearance.ForeColor = Color.Red;
            //UGridBand.Override.DataErrorRowAppearance.BackColor = Color.Red;
            //UGridBand.Override.DataErrorRowSelectorAppearance.BackColor = Color.Red;

            UGridBand.Override.HeaderStyle = HeaderStyle.Standard;
            //Thiết lập màu cho BackColor
            UGrid.DisplayLayout.Appearance.BackColor = Color.White;
            //Thiết lập màu cho BackColor2
            UGrid.DisplayLayout.Appearance.BackColor2 = Color.FromArgb(181, 234, 253);
            UGrid.DisplayLayout.Appearance.BackGradientStyle = GradientStyle.ForwardDiagonal;
            //Thiết lập màu cho Header
            UGridBand.Override.HeaderAppearance.FontData.Bold = DefaultableBoolean.False;
            UGridBand.Override.HeaderAppearance.FontData.Italic = DefaultableBoolean.False;
            UGridBand.Override.HeaderAppearance.FontData.Name = "Tahoma";
            UGridBand.Override.HeaderAppearance.FontData.SizeInPoints = 8;
            UGridBand.Override.HeaderAppearance.ForeColor = Color.Black;

            UGridBand.Override.HeaderAppearance.BackColor = Color.FromArgb(181, 234, 253);
            UGridBand.Override.HeaderAppearance.BackColor2 = Color.FromArgb(33, 151, 253);
            UGridBand.Override.HeaderAppearance.BackGradientStyle = GradientStyle.Vertical;
            UGridBand.Override.RowAppearance.BorderColor = Color.DodgerBlue;
            //Thiết lập màu cho RowSelected
            UGridBand.Override.RowSelectorAppearance.BackColor = Color.FromArgb(181, 234, 253);
            UGridBand.Override.RowSelectorAppearance.BackColor2 = Color.FromArgb(33, 151, 253);
            UGridBand.Override.RowSelectorAppearance.BackGradientStyle = GradientStyle.Vertical;
            //Thiết lập màu cho SelectRow
            UGridBand.Override.SelectedRowAppearance.BackColor = Color.FromArgb(181, 234, 253);
            UGridBand.Override.SelectedRowAppearance.BackColor2 = Color.FromArgb(33, 151, 253);
            UGridBand.Override.SelectedRowAppearance.BackGradientStyle = GradientStyle.Vertical;

            UGridBand.Override.RowSpacingBefore = 0;

            Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance();
            appearance3.BackColor = System.Drawing.Color.White;
            appearance3.BackColor2 = System.Drawing.Color.LightGray;
            appearance3.BackGradientAlignment = Infragistics.Win.GradientAlignment.Form;
            appearance3.BackGradientStyle = Infragistics.Win.GradientStyle.Horizontal;
            appearance3.FontData.BoldAsString = "True";
            appearance3.TextHAlign = Infragistics.Win.HAlign.Left;
            UGrid.DisplayLayout.CaptionAppearance = appearance3;
            //UGrid.DisplayLayout.CaptionVisible = Infragistics.Win.DefaultableBoolean.True;
        }
        public static void SetGridStyle(UltraGrid UGGrid, AutoFitStyle ColumnFitStyle)
        {
            UltraGridControls.SetGridStyle(UGGrid);
            UGGrid.DisplayLayout.AutoFitStyle = ColumnFitStyle;
        }
        public static void SetGridStyle(UltraGrid UGGrid, AutoFitStyle ColumnFitStyle, Infragistics.Win.UltraWinGrid.CellClickAction cellClickAction)
        {
            UltraGridControls.SetGridStyle(UGGrid, ColumnFitStyle);                  
            UGGrid.DisplayLayout.Override.CellClickAction = cellClickAction;          
        }
        #endregion
        #region  Keyup in Grid

        /// <summary>
		/// Quản lý di chuyển trong grid sử dụng các phím chức năng.
		/// </summary>
		/// <param name="ugMain">Grid dùng để gán sự kiện di chuyển.</param>
		/// <param name="e"> KeyEventArgs <see cref="System.Windows.Forms.KeyEventArgs"/> instance containing the event data.</param>
		// Người tạo : datlt Ngày tạo (dd/mm/yyyy): 27/03/2006 6:46 PM
		public static void moveArround(UltraGrid ugMain, System.Windows.Forms.KeyEventArgs e)
		{
            if (ugMain.Rows.Count == 0) return;

			if(ugMain.Rows != null && (ugMain.ActiveRow.Selected || ugMain.Selected.Rows.Count != 0))
				return;			
			Boolean blnFlag = false;			
			if(ugMain.ActiveCell!=null)
				blnFlag = ugMain.ActiveCell.CanEnterEditMode; 			
			
			{
				switch(e.KeyCode)
				{
					case Keys.Enter:					
						ugMain.PerformAction(UltraGridAction.ExitEditMode,false,false);
						ugMain.PerformAction(UltraGridAction.BelowCell,false,false);					
						e.Handled = true;
						ugMain.PerformAction(UltraGridAction.EnterEditMode,false,false);	
						break;
					case Keys.Up:
						if(blnFlag)
						{
							ugMain.PerformAction(UltraGridAction.ExitEditMode,false,false);
							ugMain.PerformAction(UltraGridAction.AboveCell,false,false);
							e.Handled = true;
							ugMain.PerformAction(UltraGridAction.EnterEditMode,false,false);
						} // if
						break;
					case Keys.Left:
						if(blnFlag)
						{
							ugMain.PerformAction(UltraGridAction.ExitEditMode,false,false);
							ugMain.PerformAction(UltraGridAction.PrevCellByTab,false,false);
							e.Handled = true;
							ugMain.PerformAction(UltraGridAction.EnterEditMode,false,false);
						} // if
						break;
					case Keys.Right:
						if(blnFlag)
						{
							ugMain.PerformAction(UltraGridAction.ExitEditMode,false,false);
							ugMain.PerformAction(UltraGridAction.NextCellByTab,false,false);
							e.Handled = true;
							ugMain.PerformAction(UltraGridAction.EnterEditMode,false,false);
						} // if
						break;
					case Keys.Down:	
						if(blnFlag)
						{
							ugMain.PerformAction(UltraGridAction.ExitEditMode,false,false);
							ugMain.PerformAction(UltraGridAction.BelowCell,false,false);
							e.Handled = true;
							ugMain.PerformAction(UltraGridAction.EnterEditMode,false,false);
						} // if
						break;
					case Keys.End:
						if(blnFlag)
						{
							ugMain.PerformAction(UltraGridAction.LastRowInGrid,false,false);
							e.Handled = true;
							ugMain.PerformAction(UltraGridAction.EnterEditMode,false,false);
						} // if
						break;
					case Keys.Delete:
						e.Handled = false;
						break;	
				} // switch
			} // block
		} // moveArround(ugMain, e)
		#endregion
	} // class UltraGridControls
} // namespace QLNHK.HETHONG
